<template>
  <div>
    <el-form :model="form" label-width="130px" :rules="rules" ref="form" style="margin-top: -12px">
      <el-form-item label="价格设置" class="one-label">
        <!-- 零售价 -->
        <el-form-item v-show="form.skuFlag == 0 && fromListPage == 30" label="零售价：" label-width="170px" prop="sellPrice">
          <el-input v-model="form.sellPrice" class="short-input width-per-50" @keyup.native="form.sellPrice = checkInputNum(form.sellPrice)" placeholder="例如：100">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <!-- 样品价 -->
        <el-form-item v-show="form.skuFlag == 0 && fromListPage == 30 && enterpriseConfig.anchorSelectionAuthority == '1'" label="样品价：" label-width="170px" prop="specimenPrice">
          <el-input v-model="form.specimenPrice" class="short-input width-per-50" @keyup.native="form.specimenPrice = checkInputNum(form.specimenPrice)" placeholder="例如：100">
            <template slot="append">元</template>
          </el-input>
          <div class="tips">填空则主播小程序买样价格按零售价-主播推广佣金计算</div>
        </el-form-item>
        <!-- 划线价 -->
        <el-form-item v-show="form.skuFlag == 0" label="划线价：" label-width="170px" prop="scribingPrice">
          <el-input v-model="form.scribingPrice" class="short-input width-per-50" @keyup.native="form.scribingPrice = checkInputNum(form.scribingPrice)" placeholder="例如：100">
            <template slot="append">元</template>
          </el-input>
          <div class="tips">划线价在商品详情会以划线形式显示</div>
        </el-form-item>
        <!-- 运费 -->
        <el-form-item v-if=" getVersionType() != 5 && fromListPage == 30" label="运费" class="width-per-50" label-width="170px" prop="postFee">
          <el-radio v-model="form.postFeeType" label="10">统一运费</el-radio>
          <el-input v-model="form.postFee" class="width-per-50" min="0">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item v-if=" getVersionType() != 5 && fromListPage == 30 && enterpriseConfig.deliveryTemplateAuthority == 1" label-width="170px">
          <el-radio v-model="form.postFeeType" label="11">货号运费模板</el-radio>
          <el-select v-model="form.deliveryTemplateId" placeholder="">
            <el-option v-for="(item, index) in deliveryTemplates" :key="index" :label="item.templateName" :value="item.templateId"></el-option>
          </el-select>
          <el-button type="text" @click.native="listDeliveryTemplate">刷新</el-button>
          <el-button type="text" @click.native="goAddTemplate" v-if="showEditButton">新增运费模板</el-button>
          <el-button type="text" @click.native="editTemplate(form.deliveryTemplateId)" v-if="showEditButton">编辑选中模版</el-button>
        </el-form-item>
        <!-- <div v-show="fromListPage == 30" class="radio-top-bar">
          <el-form-item label="提成佣金：" label-width="170px">
            <div class="tips blue">
              <p>1、实际佣金以比例乘以零售价来计算。</p>
              <p>2、比例和实际佣金将保留小数点后俩位并四舍五入。</p>
              <p>3、若商品为淘宝联盟商品，则提成及佣金是以商品利润（零售价减去供应价后的金额）为基数再按比例计算佣金。</p>
            </div>
            <el-row :gutter="20" class="mar-t-20">
              <el-col :md="24" :lg="12">
                <div class="border-d7">
                  <h3 class="gray-t-bar font-normal font-14 text-align-c mar-b-18">主播佣金设置</h3>
                  <el-form-item  label="一级合伙人：" v-if="enterpriseConfig.patternCommissionType == 2" label-width="130px" prop="anchorLevelOnePartnerRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.anchorLevelOnePartnerRatio"
                        class="width-per-35"
                        @keyup.native="form.anchorLevelOnePartnerRatio = checkInputNum(form.anchorLevelOnePartnerRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10" v-if="form.skuFlag == 0">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.anchorLevelOnePartnerRatio || 0) / 100).toFixed(2)}}</span></div>
                      <div class="pad-l-10" v-if="form.skuFlag == 1">实际佣金：<span class="font-orange-2 font-w">￥{{(maxSellPrice * (form.anchorLevelOnePartnerRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">一级合伙人自己招募或下架合伙人/招募员招募的主播产生的商品返佣</p>
                  </el-form-item>
                  <el-form-item  label="二级合伙人：" v-if="enterpriseConfig.patternCommissionType == 2" label-width="130px" prop="anchorLevelTwoPartnerRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.anchorLevelTwoPartnerRatio"
                        class="width-per-35"
                        @keyup.native="form.anchorLevelTwoPartnerRatio = checkInputNum(form.anchorLevelTwoPartnerRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.anchorLevelTwoPartnerRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">二级合伙人自己招募或下架招募员招募的主播产生的商品返佣</p>
                  </el-form-item>
                  <el-form-item  label="招募员：" v-if="enterpriseConfig.recruiterCommissionType == 2" label-width="130px" prop="anchorRecruiterRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.anchorRecruiterRatio"
                        class="width-per-35"
                        @keyup.native="form.anchorRecruiterRatio = checkInputNum(form.anchorRecruiterRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.anchorRecruiterRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">招募员自己招募的主播产生的商品返佣</p>
                  </el-form-item>
                  <el-form-item label="店铺主播：" label-width="130px" prop="anchorRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.anchorRatio"
                        class="width-per-35"
                        @keyup.native="form.anchorRatio = checkInputNum(form.anchorRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.anchorRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">主播在私域微信小程序端带货后获得的佣金</p>
                  </el-form-item>
                  <el-form-item label="平台主播：" label-width="130px" prop="anchorThirdPlatformRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.anchorThirdPlatformRatio"
                        class="width-per-35"
                        @keyup.native="form.anchorThirdPlatformRatio = checkInputNum(form.anchorThirdPlatformRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.anchorThirdPlatformRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">主播在公域抖音/快手等平台带货后获得的佣金</p>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :md="24" :lg="12">
                <div class="border-d7">
                  <h3 class="gray-t-bar font-normal font-14 text-align-c mar-b-18">小B佣金设置</h3>
                  <el-form-item  label="一级合伙人：" v-if="enterpriseConfig.patternCommissionType == 2" label-width="130px" prop="levelOnePartnerRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.levelOnePartnerRatio"
                        class="width-per-35"
                        @keyup.native="form.levelOnePartnerRatio = checkInputNum(form.levelOnePartnerRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.levelOnePartnerRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">一级合伙人自己招募或下架合伙人/招募员招募的店主产生的商品返佣</p>
                  </el-form-item>
                  <el-form-item label="二级合伙人：" v-if="enterpriseConfig.patternCommissionType == 2" label-width="130px" prop="levelTwoPartnerRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.levelTwoPartnerRatio"
                        class="width-per-35"
                        @keyup.native="form.levelTwoPartnerRatio = checkInputNum(form.levelTwoPartnerRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.levelTwoPartnerRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">二级合伙人自己招募或下架招募员招募的店主产生的商品返佣</p>
                  </el-form-item>
                  <el-form-item  label="招募员：" v-if="enterpriseConfig.recruiterCommissionType == 2" label-width="130px" prop="recruiterRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.recruiterRatio"
                        class="width-per-35"
                        @keyup.native="form.recruiterRatio = checkInputNum(form.recruiterRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.recruiterRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">招募员自己招募的店主产生的商品返佣</p>
                  </el-form-item>
                  <el-form-item label="店主：" label-width="130px" prop="distributeRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.distributeRatio"
                        class="width-per-35"
                        @keyup.native="form.distributeRatio = checkInputNum(form.distributeRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10 height-40 mar-t--16">
                        <div class="line-h-unset height-20 mar-b-1">
                          实际佣金：<span class="font-orange-2 font-w line-h-unset">￥{{(form.sellPrice * (form.distributeRatio || 0) / 100).toFixed(2)}}</span>
                        </div>
                        <div class="line-h-unset height-20">
                          <span class="font-blue-2 font-under cursor-p line-h-unset" @click="gradeClick">设置等级佣金</span>
                          <span class="font-color-9 line-h-unset">{{ gradeFlage ? '（已开启）' : '（已关闭）' }}</span>
                        </div>
                      </div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">店主的店铺卖出该商品后获得的佣金</p>
                  </el-form-item>
                  <el-form-item label="顾客分销商：" label-width="130px" prop="shareMemberRatio">
                    <div class="flex v-align-c">
                      <el-input
                        v-model="form.shareMemberRatio"
                        class="width-per-35"
                        @keyup.native="form.shareMemberRatio = checkInputNum(form.shareMemberRatio)">
                        <template slot="append">%</template>
                      </el-input>
                      <div class="pad-l-10">实际佣金：<span class="font-orange-2 font-w">￥{{(form.sellPrice * (form.shareMemberRatio || 0) / 100).toFixed(2)}}</span></div>
                    </div>
                    <p class="font-12 font-color-9 mar-0">顾客分销该商品后获得的返佣</p>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
          </el-form-item>
        </div> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import elDragDialog from '@/directive/el-dragDialog' // base on element-ui
import { getToken } from '@/utils/auth'
import { listGoodsGrade } from '@/api/goods/goodsMemberGrade'
import { listTemplate } from '@/api/sell/delivery-template.js'
import { getTaxList } from '@/api/warehouse/warehouseTaxItems'
import { getExternalCodeConfig, saveExternalCodeConfig } from '@/api/user/externalCodeConfig'

export default {
  directives: {
    // 拖动窗口
    elDragDialog
  },
  props: {
    dict: { type: Object },
    fromListPage: { type: Number, default: 30 },
    showEditButton: { type: Boolean, default: true },
    goodsId: { type: String, default: '' }
  },
  data() {
    return {
      activeName: '1',
      gradeVisible: false,
      gradeFlage: false,
      gradeList: [],
      ladderAuthFlag: false,
      updataFlag: false,
      tabDisabled: true,
      stockBoolean: false,
      token: '',
      fileLoading: false,
      loadingTotal: '0',
      showSingle: 1,
      ladderPriceList: [],
      form: {
        goodsSource: 0,
        ladderAuth: '0',
        skuFlag: '0',
        memberPrice: '',
        sellPrice: '',
        // 分销价
        distributePrice: '',
        distributeType: 1,
        distributeRatio: 0.00,
        distributeFee: '',
        shareMemberRatio: 0.00,
        shareMemberFee: '',
        levelOnePartnerRatio: 0.00,
        levelOnePartnerFee: '',
        levelTwoPartnerRatio: 0.00,
        levelTwoPartnerFee: '',
        recruiterRatio: 0.00,
        recruiterFee: '',
        anchorRatio: 0.00,
        anchorCommission: '',
        // 主播对应提成比例
        anchorLevelOnePartnerRatio: 0.00,
        anchorLevelTwoPartnerRatio: 0.00,
        anchorRecruiterRatio: 0.00,
        anchorThirdPlatformRatio: 0.00,
        // 主播结算价
        anchorPaymentsPrice: '',
        // 样品价
        specimenPrice: '',
        stock: '',
        stockWarn: '',
        supplyPrice: '',
        scribingPrice: '',
        wholesalePrice: '',
        goodsBarCode: '',
        deliveryTemplateId: '',
        wholesaleDeliveryTemplateId: '',
        externalCode: '',
        wholesaleNum: '',
        postFeeType: '10',
        postFee: '',
        // 配送方式 1：快递 2：物流
        templateType: '1',
        wholesalePostFeeType: '10',
        wholesalePostFee: '',
        supplierPostFee: '',
        ladderType: '0',
        ladderPriceList: [],
        singleTable: [],
        qualityData: [
          {
            skuPropId: -1,
            skuPropName: '',
            categoryId: '',
            skuPropValueList: [
              {
                skuPropValue: '',
                skuPropValueId: -2,
                skuPropId: -1,
                skuPropName: ''
              }
            ]
          }
        ],
        qualityTable: [],
        dataTable: [],
        // 供应价含税
        supplierTaxFlag: '1',
        taxItemsId: ''
      },
      // 最小零售价
      minSellPrice: 0.00,
      // 最大零售价
      maxSellPrice: 0.00,
      // 外部编码表单
      externalCodeConfigForm: {},
      deliveryTemplates: [],
      ids: [],
      imageIndex: '',
      fileChangeFlag: '0',
      editSkuParamSettingVisible: false,
      skuParamSettingValue: '',
      skuParamSettingLabel: '',
      skuParamSettingTitle: '批量修改SKU零售价',
      skuParamSettingType: '',
      visiblePopPrice: false,
      visiblePopDistributePrice: false,
      visiblePopMemberPrice: false,
      // 批量设置主播结算价
      visiblePopAnchorPrice: false,
      visiblePopSpecimenPrice: false,
      visiblePopScribingPrice: false,
      visiblePopWholesalePrice: false,
      visiblePopSupplyPrice: false,
      visiblePopStock: false,
      visiblePopWarnStock: false,
      visiblePopGoodsBarCode: false,
      visiblePopExternalCode: false,
      visibleDeliveryTemplateId: false,
      visibleWholesaleDeliveryTemplateId: false,
      ladderPriceListLength: '', // 用于判断是否设置了阶梯价
      rules: {
        sellPrice: [
          { max: 14, message: '零售价格长度最多输入 14 个字符' },
          { required: false, message: '请填写商品零售价', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请填写正确金额'
          }
        ],
        postFee: [
          { max: 14, message: '运费最多输入14 个字符' },
          { required: true, message: '请填写运费', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请正确输入运费'
          }
        ],
        wholesalePostFee: [
          { max: 14, message: '运费最多输入14 个字符' },
          { required: true, message: '请填写运费', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请正确输入运费'
          }
        ],
        supplierPostFee: [
          { max: 14, message: '邮费最多输入14 个字符' },
          { required: true, message: '请填写运费', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请正确输入邮费'
          }
        ],
        wholesalePrice: [
          { max: 14, message: '批发价价格长度最多输入 14 个字符' },
          { required: false, message: '请填写商品批发价', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请填写正确金额'
          }
        ],
        scribingPrice: [
          { max: 14, message: '划线价格长度最多输入 14 个字符' },
          { required: false, message: '请正确输入划线价格', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请填写正确金额'
          }
        ],
        distributeRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)/,
            message: '请填写正确分销比例'
          }
        ],
        distributeFee: [
          { max: 14, message: '微客佣金最多输入14个字符' },
          { required: false, message: '请输入微客分销佣金', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请正确输入微客分销佣金'
          }
        ],
        supplyPrice: [
          { max: 14, message: '供应价最多输入14个字符' },
          { required: false, message: '请输入供应价', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请正确输入供应价'
          }
        ],
        anchorPaymentsPrice: [
          { max: 14, message: '主播结算价最多输入14个字符' },
          { required: false, message: '请输入主播结算价', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请输入主播结算价'
          }
        ],
        specimenPrice: [
          { max: 14, message: '样品价最多输入14个字符' },
          { required: false, message: '请输入样品价', trigger: 'blur' },
          {
            pattern: /(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,2}$)/,
            message: '请正确输入样品价'
          }
        ],
        anchorLevelOnePartnerRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写一级合伙人佣金比例'
          }
        ],
        anchorLevelTwoPartnerRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写二级合伙人佣金比例'
          }
        ],
        anchorRecruiterRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写招募员佣金比例'
          }
        ],
        anchorRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写店铺主播佣金比例'
          }
        ],
        anchorThirdPlatformRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写平台主播佣金比例'
          }
        ],
        levelOnePartnerRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写一级合伙人佣金比例'
          }
        ],
        levelTwoPartnerRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写二级合伙人佣金比例'
          }
        ],
        recruiterRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写招募员佣金比例'
          }
        ],
        shareMemberRatio: [
          { required: false },
          {
            pattern: /(^(\d|[1-9]\d)(\.\d{1,2})?$)|^100$/,
            message: '请正确填写顾客分销商佣金比例'
          }
        ]
      },
      categoryId: '',
      tempList: [],
      enterpriseConfig: {
        partnerAuthority: 0,
        deliveryTemplateAuthority: 0,
        // 合伙人提成比例取用规则 1:按合伙人 2：按商品
        patternCommissionType: 1,
        // 招募员提成比例取用规则 1:按招募员 2：按商品
        recruiterCommissionType: 1
      },
      // 税目列表
      taxList: [],
      memberTitle: '会员'
    }
  },
  computed: {
  },
  // 初始化页面
  created() {
    this.token = { accessToken: getToken() }
    let templateType = '1'
    if (this.fromListPage === 31) {
      templateType = this.form.templateType
    }
    listTemplate({ enterpriseId: this.getEnterpriseId(), templateType: templateType }).then(response => {
      this.deliveryTemplates = response.data
    })
    this.initGoodsEdit()
    // 获取税目信息
    this.getTaxList()
    this.getExternalCodeConfig()
  },
  mounted() {
    const that = this
    // 监听info页面的enterpriseConfig信息
    this.$bus.$on('info.enterpriseConfig', function(data) {
      that.enterpriseConfig = data
      if (!that.form.goodsId) {
        // 新增商品，设置默认进项税税目
        that.form.taxItemsId = data.taxItemsId
      }
      if (data.warehouseAuthority === 1 && data.warehouseDeliverFlag === 1) {
        // 开启仓库库存，不允许编辑
        that.stockBoolean = true
      }
      that.memberTitle = data.memberTitle || '会员'
    })
    this.$bus.$on('goods_supplier.stockBoolean', function(stockBoolean) {
      that.stockBoolean = stockBoolean
    })
    this.$bus.$on('skuFlag', function(flag) {
      that.form.skuFlag = flag
    })
  },
  watch: {
  },
  methods: {
    // 跳转到新增运费模板页
    goAddTemplate() {
      const routeData = this.$router.resolve({
        path: '/order/order/express/delivery-template-detail/index',
        query: { }
      })
      window.open(routeData.href, '_blank')
    },
    // 编辑运费模板
    editTemplate(templateId) {
      const routeData = this.$router.resolve({
        path: '/order/order/express/delivery-template-detail/index',
        query: { templateId: templateId }
      })
      window.open(routeData.href, '_blank')
    },
    gradeClick() {
      if (this.form.memberGradeAuth === 0) {
        this.gradeFlage = false
      } else {
        this.gradeFlage = true
      }
      if (this.gradeList.length === 0) {
        listGoodsGrade(this.getEnterpriseId(), this.form.goodsId, this.form.distributeType).then(response => {
          if (response.isError) return
          this.gradeList = response.data
          this.gradeVisible = true
        })
      } else {
        this.gradeVisible = true
      }
    },
    distributeTypeChange() {
      this.gradeList = []
    },
    copyCommission() {
      this.gradeList.forEach(item => {
        this.$set(item, 'commissionRate', item.defaultCommissionRate)
      })
    },
    saveGrade() {
      if (this.gradeFlage) {
        this.form.memberGradeAuth = 1
      } else {
        this.form.memberGradeAuth = 0
      }
      if (this.gradeList.length === 0 && this.gradeFlage) {
        this.$message.error('请先设置店主等级')
        return
      }
      let flag = 0
      let flag1 = 0
      this.gradeList.forEach(item => {
        if (item.commissionRate * 1 > 100) {
          flag = 1
          return
        }
        if (item.commissionRate === '' || item.commissionRate === undefined) {
          flag1 = 1
          return
        }
      })
      if (flag === 1) {
        this.$message.error('佣金比例不能大于100')
        return
      }
      if (flag1 === 1) {
        this.$message.error('佣金不能为空')
        return
      }
      this.form.gradeList = this.gradeList
      this.gradeVisible = false
    },
    changeSelect(index) {
      this.tempList = []
      for (const item of this.form.qualityData) {
        if (item.categoryId !== '') {
          this.tempList.push(item.categoryId)
        }
      }
      const skuProp = this.form.qualityData[index]
      skuProp.skuPropId = this.getID()
      skuProp.skuPropValueList.forEach(skuPropValue => {
        skuPropValue.skuPropId = skuProp.skuPropId
        skuPropValue.skuPropName = skuProp.skuPropName
        skuPropValue.skuPropValueId = this.getID()
      })
    },
    subInputBlur() {
      if (this.form.qualityData.length === 1) {
        // 只有一个规格的，刷新一下属性名称
        const skuPropId = this.form.qualityData[0].skuPropId
        const skuPropName = this.form.qualityData[0].skuPropName
        const skuPropValueList = this.form.qualityData[0].skuPropValueList
        const singleTableList = this.form.singleTable
        for (let i = 0; i < singleTableList.length; i++) {
          singleTableList[i].skuPropId = skuPropId
          singleTableList[i].skuPropName = skuPropName
          singleTableList[i].skuPropValue = skuPropValueList[i].skuPropValue
          singleTableList[i].skuPropValueId = skuPropValueList[i].skuPropValueId
        }
        this.form.singleTable = JSON.parse(JSON.stringify(singleTableList))
      }
    },
    setQualityTable(dataTable) {
      const skuValueMap = new Map()
      for (let i = 0; i < dataTable.length; i++) {
        skuValueMap.set(dataTable[i].skuValueIds, dataTable[i])
      }

      const qualityTable = this.form.qualityTable
      const qualityData = this.form.qualityData

      if (qualityData.length === 1) {
        const skuPropValueList = qualityData[0].skuPropValueList
        const skuPropId = qualityData[0].skuPropId
        const skuPropName = qualityData[0].skuPropName

        for (let i = 0; i < skuPropValueList.length; i++) {
          skuPropValueList[i].skuPropId = skuPropId
          skuPropValueList[i].skuPropName = skuPropName
          const skuPropValueId = skuPropValueList[i].skuPropValueId
          const array = []
          array.push(skuPropValueId)
          const skuValueKey = array.sort().toString()
          const skuValueObj = skuValueMap.get(skuValueKey)
          if (!skuValueObj) {
            console.log('查无sku信息：' + skuValueKey)
            continue
          }
          if (skuValueObj.skuId) {
            skuPropValueList[i].skuId = skuValueObj.skuId
          }
          skuPropValueList[i].imageUrl = this.$utils.isExist(skuValueObj.imageUrl) ? skuValueObj.imageUrl : ''
          skuPropValueList[i].price = this.$utils.isExist(skuValueObj.price) ? skuValueObj.price : ''
          this.minSellPrice = skuPropValueList[i].price
          this.maxSellPrice = skuPropValueList[i].price
          // 主播结算价
          skuPropValueList[i].anchorPaymentsPrice = this.$utils.isExist(skuValueObj.anchorPaymentsPrice) ? skuValueObj.anchorPaymentsPrice : ''
          // 样品价
          skuPropValueList[i].specimenPrice = this.$utils.isExist(skuValueObj.specimenPrice) ? skuValueObj.specimenPrice : ''
          skuPropValueList[i].memberPrice = this.$utils.isExist(skuValueObj.memberPrice) ? skuValueObj.memberPrice : ''
          skuPropValueList[i].scribingPrice = this.$utils.isExist(skuValueObj.scribingPrice) ? skuValueObj.scribingPrice : ''
          skuPropValueList[i].wholesalePrice = this.$utils.isExist(skuValueObj.wholesalePrice) ? skuValueObj.wholesalePrice : ''
          skuPropValueList[i].goodsBarCode = this.$utils.isExist(skuValueObj.goodsBarCode) ? skuValueObj.goodsBarCode : ''
          skuPropValueList[i].deliveryTemplateId = this.$utils.isExist(skuValueObj.deliveryTemplateId) ? skuValueObj.deliveryTemplateId : ''
          skuPropValueList[i].wholesaleDeliveryTemplateId = this.$utils.isExist(skuValueObj.wholesaleDeliveryTemplateId) ? skuValueObj.wholesaleDeliveryTemplateId : ''
          skuPropValueList[i].externalCode = this.$utils.isExist(skuValueObj.externalCode) ? skuValueObj.externalCode : ''
          skuPropValueList[i].supplyPrice = this.$utils.isExist(skuValueObj.supplyPrice) ? skuValueObj.supplyPrice : ''
          skuPropValueList[i].stock = this.$utils.isExist(skuValueObj.stock) ? skuValueObj.stock : '0'
          skuPropValueList[i].warnStock = this.$utils.isExist(skuValueObj.warnStock) ? skuValueObj.warnStock : ''
        }

        // this.form.singleTable = skuPropValueList
        const obj = JSON.stringify(skuPropValueList)
        this.form.singleTable = JSON.parse(obj)
      } else {
        const array = []
        for (let i = 0; i < qualityTable.length; i++) {
          const item = qualityTable[i]
          const skuPropValueList = []
          for (const key in item) {
            if (this.$utils.isExist(item[key].skuPropId)) {
              const skuPropValueId = item[key].skuPropValueId
              skuPropValueList.push(skuPropValueId)
            }
          }

          const obj = {}
          const skuValueKey = skuPropValueList.sort().toString()
          const skuValueObj = skuValueMap.get(skuValueKey)
          if (skuValueObj != null) {
            if (skuValueObj.skuId) {
              obj.skuId = skuValueObj.skuId
            }
            for (const key in item) {
              obj[key] = item[key]
            }
            obj.imageUrl = this.$utils.isExist(skuValueObj.imageUrl) ? skuValueObj.imageUrl : ''
            obj.price = this.$utils.isExist(skuValueObj.price) ? skuValueObj.price : ''
            // 最低和最高零售价
            if (obj.price !== '' && obj.price > this.maxSellPrice) {
              this.maxSellPrice = obj.price
            }
            if (obj.price !== '' && obj.price < this.minSellPrice) {
              this.minSellPrice = obj.price
            }
            // 主播结算价
            obj.anchorPaymentsPrice = this.$utils.isExist(skuValueObj.anchorPaymentsPrice) ? skuValueObj.anchorPaymentsPrice : ''
            // 样品价
            obj.specimenPrice = this.$utils.isExist(skuValueObj.specimenPrice) ? skuValueObj.specimenPrice : ''
            obj.memberPrice = this.$utils.isExist(skuValueObj.memberPrice) ? skuValueObj.memberPrice : ''
            obj.scribingPrice = this.$utils.isExist(skuValueObj.scribingPrice) ? skuValueObj.scribingPrice : ''
            obj.wholesalePrice = this.$utils.isExist(skuValueObj.wholesalePrice) ? skuValueObj.wholesalePrice : ''
            obj.goodsBarCode = this.$utils.isExist(skuValueObj.goodsBarCode) ? skuValueObj.goodsBarCode : ''
            obj.deliveryTemplateId = this.$utils.isExist(skuValueObj.deliveryTemplateId) ? skuValueObj.deliveryTemplateId : ''
            obj.wholesaleDeliveryTemplateId = this.$utils.isExist(skuValueObj.wholesaleDeliveryTemplateId) ? skuValueObj.wholesaleDeliveryTemplateId : ''
            obj.externalCode = this.$utils.isExist(skuValueObj.externalCode) ? skuValueObj.externalCode : ''
            obj.supplyPrice = this.$utils.isExist(skuValueObj.supplyPrice) ? skuValueObj.supplyPrice : ''
            obj.stock = this.$utils.isExist(skuValueObj.stock) ? skuValueObj.stock : '0'
            obj.warnStock = this.$utils.isExist(skuValueObj.warnStock) ? skuValueObj.warnStock : ''
            array.push(obj)
          } else {
            console.log('sku异常' + skuValueKey)
          }
        }
        this.form.qualityTable = array
      }
    },
    getID(length) {
      const ids = this.ids
      const id = -parseInt(Math.round(Math.random() * 100000000))
      if (ids.indexOf(id) > 0) {
        this.getID()
      } else {
        ids.push(id)
        this.ids = ids
        return id
      }
    },
    changeImage(index) {
      this.imageIndex = index
    },
    beforeUpload(file) {
      this.fileChangeFlag = '0'
      const isJPG = file.type === 'image/jpeg'
      const isGIF = file.type === 'image/gif'
      const isPNG = file.type === 'image/png'
      const isBMP = file.type === 'image/bmp'

      if (!isJPG && !isGIF && !isPNG && !isBMP) {
        this.$message.error('上传图片必须是JPG/GIF/PNG/BMP 格式!')
      }
      this.fileLoading = true
      return isJPG || isBMP || isGIF || isPNG
    },
    getLoading(index) {
      const that = this
      if (that.loadingTotal === '1' && this.imageIndex === index) {
        return true
      } else {
        return false
      }
    },
    handleUploadSuccess(res, file) {
      this.loadingTotal = '0'
      if (res.code === 101) {
        const qualityData = this.form.qualityData
        if (qualityData.length === 1) {
          const singleTable = this.form.singleTable
          for (let i = 0; i < singleTable.length; i++) {
            const imageIndex = this.imageIndex
            if (imageIndex * 1 === i) {
              singleTable[i].imageUrl = res.data[0]
            }
          }
        } else {
          const imageIndex = this.imageIndex
          const qualityTable = this.form.qualityTable
          for (let i = 0; i < qualityTable.length; i++) {
            if (imageIndex * 1 === i) {
              qualityTable[i].imageUrl = res.data[0]
            }
          }
        }
      } else {
        this.$message({
          type: 'error',
          message: res.msg
        })
        return false
      }
      this.$forceUpdate()
    },
    initGoodsEdit() {
      const that = this
      this.$bus.$on('goods.edit.data', function(data) {
        that.form.goodsId = data.goodsId
        that.form.goodsSource = data.goodsSource || 0
        if (data.goodsSource === 0) {
          that.updataFlag = false
        } else {
          that.updataFlag = true
        }
        that.form.memberGradeAuth = data.memberGradeAuth
        if (that.getVersionType() * 1 === 5) {
          // 社区版，供应商价格可编辑
          that.updataFlag = false
        }
        if (that.enterpriseConfig.warehouseAuthority === 1 && that.enterpriseConfig.warehouseDeliverFlag === 1) {
          that.stockBoolean = true
        }
        const skuFlag = that.$utils.isExist(data.skuFlag) ? data.skuFlag + '' : '0'
        that.form.skuFlag = skuFlag
        that.form.supplierPostFee = that.$utils.isExist(data.supplierPostFee) ? data.supplierPostFee : '0'
        that.form.deliveryTemplateId = data.deliveryTemplateId
        that.form.postFeeType = that.$utils.isExist(data.postFeeType) ? data.postFeeType.toString() : '10'
        that.form.postFee = that.$utils.isExist(data.postFee) ? data.postFee : '0'
        that.form.wholesaleDeliveryTemplateId = data.wholesaleDeliveryTemplateId
        that.form.wholesalePostFeeType = that.$utils.isExist(data.wholesalePostFeeType) ? data.wholesalePostFeeType.toString() : '10'
        that.form.wholesalePostFee = that.$utils.isExist(data.wholesalePostFee) ? data.wholesalePostFee : '0'
        // 供应价含税
        that.form.supplierTaxFlag = that.$utils.isExist(data.supplierTaxFlag) ? data.supplierTaxFlag.toString() : '1'
        // 进项税税目
        that.form.taxItemsId = that.$utils.isExist(data.taxItemsId) ? data.taxItemsId : ''
        that.form.sellPrice = that.$utils.isExist(data.sellPrice) ? data.sellPrice : ''
        that.form.distributeRatio = that.$utils.isExist(data.distributeRatio) ? data.distributeRatio + '' : 0.00
        that.form.stock = that.$utils.isExist(data.stock) ? data.stock + '' : '0'
        that.form.stockWarn = that.$utils.isExist(data.stockWarn) ? data.stockWarn + '' : ''
        that.form.distributeType = that.$utils.isExist(data.distributeType) ? data.distributeType : 1
        that.form.distributeRatio = that.$utils.isExist(data.distributeRatio) ? data.distributeRatio + '' : 0.00
        that.form.distributeFee = that.$utils.isExist(data.distributeFee) ? data.distributeFee : ''
        that.form.shareMemberRatio = that.$utils.isExist(data.shareMemberRatio) ? data.shareMemberRatio + '' : 0.00
        that.form.shareMemberFee = that.$utils.isExist(data.shareMemberFee) ? data.shareMemberFee : ''
        that.form.anchorRatio = that.$utils.isExist(data.anchorRatio) ? data.anchorRatio + '' : 0.00
        that.form.anchorCommission = that.$utils.isExist(data.anchorCommission) ? data.anchorCommission : ''
        that.form.levelOnePartnerRatio = that.$utils.isExist(data.levelOnePartnerRatio) ? data.levelOnePartnerRatio + '' : 0.00
        that.form.levelOnePartnerFee = that.$utils.isExist(data.levelOnePartnerFee) ? data.levelOnePartnerFee : ''
        that.form.levelTwoPartnerRatio = that.$utils.isExist(data.levelTwoPartnerRatio) ? data.levelTwoPartnerRatio + '' : 0.00
        that.form.levelTwoPartnerFee = that.$utils.isExist(data.levelTwoPartnerFee) ? data.levelTwoPartnerFee : ''
        that.form.recruiterRatio = that.$utils.isExist(data.recruiterRatio) ? data.recruiterRatio + '' : 0.00
        that.form.recruiterFee = that.$utils.isExist(data.recruiterFee) ? data.recruiterFee : ''
        // 主播对应提成比例
        that.form.anchorLevelOnePartnerRatio = that.$utils.isExist(data.anchorLevelOnePartnerRatio) ? data.anchorLevelOnePartnerRatio : 0.00 + ''
        that.form.anchorLevelTwoPartnerRatio = that.$utils.isExist(data.anchorLevelTwoPartnerRatio) ? data.anchorLevelTwoPartnerRatio : 0.00
        that.form.anchorRecruiterRatio = that.$utils.isExist(data.anchorRecruiterRatio) ? data.anchorRecruiterRatio : 0.00
        that.form.anchorThirdPlatformRatio = that.$utils.isExist(data.anchorThirdPlatformRatio) ? data.anchorThirdPlatformRatio : 0.00
        that.form.supplyPrice = that.$utils.isExist(data.supplyPrice) ? data.supplyPrice + '' : '0'
        // 主播结算价
        that.form.anchorPaymentsPrice = that.$utils.isExist(data.anchorPaymentsPrice) ? data.anchorPaymentsPrice : ''
        // 样品价
        that.form.specimenPrice = that.$utils.isExist(data.specimenPrice) ? data.specimenPrice : ''
        // 分销价
        that.form.distributePrice = that.$utils.isExist(data.distributePrice) ? data.distributePrice : ''
        that.form.scribingPrice = that.$utils.isExist(data.scribingPrice) ? data.scribingPrice + '' : ''
        that.form.memberPrice = that.$utils.isExist(data.memberPrice) ? data.memberPrice + '' : ''
        that.form.wholesalePrice = that.$utils.isExist(data.wholesalePrice) ? data.wholesalePrice + '' : ''
        that.form.goodsBarCode = that.$utils.isExist(data.goodsBarCode) ? data.goodsBarCode + '' : ''
        that.form.deliveryTemplateId = that.$utils.isExist(data.deliveryTemplateId) ? data.deliveryTemplateId + '' : ''
        that.form.wholesaleDeliveryTemplateId = that.$utils.isExist(data.wholesaleDeliveryTemplateId) ? data.wholesaleDeliveryTemplateId + '' : ''
        that.form.externalCode = that.$utils.isExist(data.externalCode) ? data.externalCode + '' : ''
        that.form.wholesaleNum = that.$utils.isExist(data.wholesaleNum) ? data.wholesaleNum + '' : ''
        that.form.ladderAuth = that.$utils.isExist(data.ladderAuth) ? data.ladderAuth + '' : ''
        that.form.templateType = that.$utils.isExist(data.templateType) ? data.templateType + '' : ''
        that.ladderPriceList = data.ladderPriceList
        if (skuFlag === '1') {
          const qualityData = data.qualityData
          if (qualityData.length === 1) {
            const skuPropValueList = qualityData[0].skuPropValueList
            for (let i = 0; i < skuPropValueList.length; i++) {
              skuPropValueList[i].imageUrl = ''
              skuPropValueList[i].price = ''
              // 主播结算价
              skuPropValueList[i].anchorPaymentsPrice = ''
              // 样品价
              skuPropValueList[i].specimenPrice = ''
              skuPropValueList[i].memberPrice = ''
              // 分销价
              skuPropValueList[i].distributePrice = ''
              skuPropValueList[i].scribingPrice = ''
              skuPropValueList[i].wholesalePrice = ''
              skuPropValueList[i].goodsBarCode = ''
              skuPropValueList[i].deliveryTemplateId = ''
              skuPropValueList[i].wholesaleDeliveryTemplateId = ''
              skuPropValueList[i].externalCode = ''
              skuPropValueList[i].supplyPrice = ''
              skuPropValueList[i].stock = '0'
              skuPropValueList[i].warnStock = ''
            }
          }
          that.form.qualityData = qualityData
          that.form.dataTable = data.qualityTable
          that.setQualityTable(data.qualityTable)
        }
        that.listDeliveryTemplate()
      })
    },
    ladderAuthClick() {
      this.ladderAuthFlag = true
    },
    addLadderPrice() {
      this.ladderPriceList.push({})
    },
    delLadderPrice(subIndex) {
      if (this.ladderPriceList && this.ladderPriceList.length > 1) {
        this.ladderPriceList.splice(subIndex, 1)
      }
    },
    saveLadderPrice() {
      // 校验阶梯价
      if (this.ladderPriceList && this.ladderPriceList.length > 0) {
        if (!Number(this.ladderPriceList[0].ladderNum) > 0) {
          this.$message({
            type: 'error',
            message: '购买数量要大于0'
          })
          return
        }
        if (!parseFloat(this.ladderPriceList[0].ladderPrice) > 0) {
          this.$message({
            type: 'error',
            message: '批发价要大于0'
          })
          return
        }
      }
      if (this.ladderPriceList && this.ladderPriceList.length > 1) {
        for (let i = 0; i < this.ladderPriceList.length - 1; i++) {
          if (!Number(this.ladderPriceList[i + 1].ladderNum) > 0) {
            this.$message({
              type: 'error',
              message: '购买数量要大于0'
            })
            return
          }
          if (!parseFloat(this.ladderPriceList[i + 1].ladderPrice) > 0) {
            this.$message({
              type: 'error',
              message: '批发价要大于0'
            })
            return
          }
          if (Number(this.ladderPriceList[i].ladderNum) >= Number(this.ladderPriceList[i + 1].ladderNum)) {
            this.$message({
              type: 'error',
              message: '购买数量要大于上一级阶梯'
            })
            return
          }
          if (parseFloat(this.ladderPriceList[i].ladderPrice) <= parseFloat(this.ladderPriceList[i + 1].ladderPrice)) {
            this.$message({
              type: 'error',
              message: '批发价要小于上一级阶梯'
            })
            return
          }
        }
      }
      this.form.ladderPriceList = JSON.parse(
        JSON.stringify(this.ladderPriceList)
      )
      this.ladderAuthFlag = false
    },
    checkForm() {
      const distributeType = this.form.distributeType
      // 佣金比例设置
      const levelOnePartnerRatio = this.form.levelOnePartnerRatio
      const levelTwoPartnerRatio = this.form.levelTwoPartnerRatio
      const recruiterRatio = this.form.recruiterRatio
      const anchorRatio = this.form.anchorRatio
      const anchorThirdPlatformRatio = this.form.anchorThirdPlatformRatio
      const anchorLevelOnePartnerRatio = this.form.anchorLevelOnePartnerRatio
      const anchorLevelTwoPartnerRatio = this.form.anchorLevelTwoPartnerRatio
      const anchorRecruiterRatio = this.form.anchorRecruiterRatio
      const distributeRatio = this.form.distributeRatio
      const shareMemberRatio = this.form.shareMemberRatio
      const totalRatio = levelOnePartnerRatio * 1 + levelTwoPartnerRatio * 1 + recruiterRatio * 1 + anchorRatio * 1 + anchorThirdPlatformRatio * 1 + anchorLevelOnePartnerRatio * 1 + anchorLevelTwoPartnerRatio * 1 + anchorRecruiterRatio * 1 + distributeRatio * 1 + shareMemberRatio * 1
      if (totalRatio > 100) {
        this.$message({ type: 'error', message: '合计佣金金额不能大于零售价' })
        return
      }
      // 需要校验的集合
      const checkArrays = []
      // if (skuFlag === '0') {
      //   checkArrays.push('sellPrice')
      //   checkArrays.push('stock')
      // }
      if (this.fromListPage === 30 && this.form.postFeeType * 1 === 10) {
        checkArrays.push('postFee')
      }
      if (this.fromListPage === 31 && this.form.wholesalePostFeeType * 1 === 10) {
        checkArrays.push('wholesalePostFee')
      }
      checkArrays.push('supplierPostFee')
      if (distributeType === 1) {
        checkArrays.push('distributeRatio')
      } else if (distributeType === 2) {
        checkArrays.push('distributeFee')
      }
      checkArrays.push('scribingPrice')
      // checkArrays.push('unrealSalesNum')
      checkArrays.push('stockWarn')
      let ret = true
      let message = ''
      this.$refs.form.validateField(checkArrays, (valid) => {
        if (valid !== '') {
          message = valid
          ret = false
          return false
        }
      })
      if (!ret) {
        this.$message({
          type: 'error',
          message: message
        })
        return false
      }
      if (this.fromListPage === 31 && !this.form.wholesaleNum && this.form.ladderAuth === '0') {
        this.$message({
          type: 'error',
          message: '起批数不能为空'
        })
        return false
      }
      // 校验阶梯价
      if (this.ladderPriceList && this.ladderPriceList.length > 0) {
        if (!Number(this.ladderPriceList[0].ladderNum) > 0) {
          this.$message({
            type: 'error',
            message: '购买数量要大于0'
          })
          this.ladderAuthFlag = true
          return false
        }
        if (!parseFloat(this.ladderPriceList[0].ladderPrice) > 0) {
          this.$message({
            type: 'error',
            message: '批发价要大于0'
          })
          this.ladderAuthFlag = true
          return false
        }
      }
      if (this.ladderPriceList && this.ladderPriceList.length > 1) {
        for (let i = 0; i < this.ladderPriceList.length - 1; i++) {
          if (!Number(this.ladderPriceList[i + 1].ladderNum) > 0) {
            this.$message({
              type: 'error',
              message: '购买数量要大于0'
            })
            return
          }
          if (!parseFloat(this.ladderPriceList[i + 1].ladderPrice) > 0) {
            this.$message({
              type: 'error',
              message: '批发价要大于0'
            })
            return
          }
          if (Number(this.ladderPriceList[i].ladderNum) >= Number(this.ladderPriceList[i + 1].ladderNum)) {
            this.$message({
              type: 'error',
              message: '购买数量要大于上一级阶梯'
            })
            this.ladderAuthFlag = true
            return false
          }
          if (parseFloat(this.ladderPriceList[i].ladderPrice) <= parseFloat(this.ladderPriceList[i + 1].ladderPrice)) {
            this.$message({
              type: 'error',
              message: '批发价要小于上一级阶梯'
            })
            this.ladderAuthFlag = true
            return false
          }
        }
      }
      this.form.ladderPriceList = JSON.parse(
        JSON.stringify(this.ladderPriceList)
      )
      return true
    },
    changeTemplateType() {
      if (this.fromListPage === 31) {
        this.form.wholesaleDeliveryTemplateId = ''
        this.listDeliveryTemplate()
      }
    },
    listDeliveryTemplate() {
      let templateType = '1'
      if (this.fromListPage === 31) {
        templateType = this.form.templateType
      }
      listTemplate({ enterpriseId: this.getEnterpriseId(), templateType: templateType }).then(response => {
        this.deliveryTemplates = response.data
      })
    },
    // 获取用户的税目列表
    getTaxList() {
      getTaxList(this.getEnterpriseId()).then(response => {
        if (response.isError) {
          return
        }
        this.taxList = response.data
      })
    },
    // 获取企业外部编码配置
    getExternalCodeConfig() {
      getExternalCodeConfig(this.getEnterpriseId()).then(response => {
        if (response.isError) return
        if (response.data !== undefined) {
          this.externalCodeConfigForm = response.data
        }
      })
    },
    // 生成外部编码
    generateExternalCode() {
      // 系统随机和自定义才可点击生成
      if (this.externalCodeConfigForm.contentType === 3) {
        if (!this.externalCodeConfigForm.customizeContent) {
          this.$message({ type: 'error', message: '自定义内容不能为空' })
          return
        } else {
          // 保存自定义文本
          saveExternalCodeConfig(this.externalCodeConfigForm).then(response => {
            if (response.isError) return
            this.visiblePopExternalCode = false
          })
        }
      } else {
        this.visiblePopExternalCode = false
      }
    }
  }
}
</script>


<style lang="less" scoped>
.table-container {
  min-height: auto;
}

.quality-bar {
  background: #f2f2f2;
  border: #e4e4e4 1px solid;
  padding: 10px;

  .close-quality {
    color: #515151;
  }

  .close-sub {
    color: #aeaeae;
    position: absolute;
    right: -6px;
    top: -6px;
    font-size: 18px;
  }

  .qta-item:before {
    content: '';
    position: absolute;
    left: 12px;
    top: 34px;
    width: 1px;
    height: 46px;
    background: #bcbcbc;
  }

  .qta-item:after {
    content: '';
    position: absolute;
    left: 12px;
    top: 79px;
    width: 19px;
    height: 1px;
    background: #bcbcbc;
  }
}

.span-bar {
  padding: 0 50px;
}

.remove-btn {
  padding: 7px 6px !important;
}

.long-input {
  width: 80%;
}

.long-input-2 {
  width: 55%;
  margin-right: 5%;
}

.long-input-3 {
  width: 55%;
}

.short-input {
  width: 20%;
}

.short-input-2 {
  width: 25%;
}
.default-input {
  width: 80%;
  @media screen and (max-width: 1440px) {
    width: 100%;
  }
}

.tips {
  color: gray;
  font-size: 12px;
  line-height: 1.2;
  padding-top: 5px;
}

.picture {
  width: 130px;
  height: 130px;
  display: block;
}

.pic-bar {
  position: relative;

  .close-icon {
    position: absolute;
    right: -30px;
    top: -11px;
    width: 31px;
    height: 40px;
    padding: 0 7px;
    cursor: pointer;
  }

  span {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 100%;
    display: block;
    color: #fff;
    text-align: center;
    padding: 3px 0;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
  }
}

.pic-add {
  background: #fff;
  border: #d3d3d3 1px dashed;
  border-radius: 5px;
  padding: 0 45px;
}

.input-bar-0 {
  width: 35% !important;
}

.input-bar-1 {
  width: 40%;
  margin-bottom: 5px !important;
}

.input-bar-2 {
  width: 60%;
  margin-bottom: 5px !important;
}

.input-bar-3 {
  width: 100%;
  margin-bottom: 5px !important;
}

.input-bar-4 {
  width: 35% !important;
}

.width-input-1 {
  width: 100% !important;
}

.width-input-2 {
  width: 35% !important;
}

.width-input-3 {
  width: 30% !important;
}

.width-date {
  width: 200px !important;
}

.gray-bar {
  background: #fff;
  padding: 5px 0 0 0;
  margin-bottom: 20px;
}

.gray-active {
  margin-right: 20px;
  // padding: 15px 13px;

  &.active {
    background: #fff;
  }
}

.radio-top-bar {
  margin-bottom: -22px;
  /deep/ .el-input-group__append, .el-input-group__prepend{
    padding: 0 10px;
  }
}

.noraml-height {
  height: 40px;
}

.border-d7 {
  /deep/ .el-input__inner {
    padding: 0;
    padding-left: 10px;
  }
}
.sub-list {
  /deep/ .el-collapse{
    border-top: 0px solid #fff !important;
    border-bottom: 0px solid #fff !important;
  }
  /deep/ .el-collapse-item__header {
    border-bottom: 0px;
  }
}
</style>
